<template>
  <div id="app">
    <keep-alive>
      <router-view v-if="$route.meta.keepAlive"></router-view>
    </keep-alive>
    <router-view v-if="!$route.meta.keepAlive"></router-view>
  </div>
</template>

<script>
// import Cookies from 'js-cookie'
import detail from './page/detail/art-detail'
import {getUrlKey} from './utils/utils'

// const appid = 'wx6f26fe9e1b980622'
export default {
  name: 'App',
  components: {
    detail
  },
  data() {
    return {
      init: true
    }
  },
  beforeMount() {
    let token = getUrlKey('token')
    if (token) {
      sessionStorage.setItem('token', token)
      sessionStorage.setItem('classID', getUrlKey('classID'))
    }
  },
  /*mounted(){
    const sk=Cookies.get('sessionKey')||'';
    if(!sk){
      let code=getUrlKey('code')||''
      if(!code){
        let href=encodeURIComponent(window.location.href.split('?')[0]);
        // console.log(href)
        window.location.replace(`https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${href}&response_type=code&scope=snsapi_base&connect_redirect=1#wechat_redirect`)
      } else {
        this.$vux.loading.show({text:'登录中'})
        this.$post('/api/user/login',{code}).then(res=>{
          if(res.code===0){
            Cookies.set('UserID',res.data.UserID)
            Cookies.set('sessionKey',res.data.sessionKey,{ expires: 0.08 })
            // window.history.go(-1);
            this.init=true
          }else {
            this.$vux.loading.show({
              type:'cancel',
              text: '登录失效，请退出重新登录'
            })
          }
        })
      }
    }else {
      this.init=true
    }

  }*/
}
</script>

<style lang="less">
@import '~vux/src/styles/reset.less';
@import './style/reset.less';
@import './style/var.less';

#app {
  background-color: @gray-light;
}
</style>
